<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模块列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" th:href="@{/resource/css/bootstrap.min.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/font-awesome.min.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/animate.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/style.css}" />
    <link th:href="@{/resource/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet">
    <link th:href="@{/resource/css/plugins/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/resource/css/plugins/toastr/toastr.min.css}" />
    <style>
        .file {
            position: relative;
            display: inline-block;
            width: 200px;
            background: #1ab394;
            border: 1px solid #1ab394;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #ffffff;
            text-decoration: none;
            text-indent: 0;
            text-align: center;
            line-height: 20px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
    </style>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="row">
                        <div class="col-sm-9">  <h5>专题管理 &nbsp;/&nbsp;  <small>编辑专题</small></h5></div>
                        <div class="col-sm-3">
                            <button type="button"  id="back_but" class="btn btn-white">返回</button>
                        </div>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="commentForm" method="post">

                        <div class="form-group">
                            <div class="col-md-7">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">标题：</label>
                                    <div class="col-sm-9">
                                        <textarea id="title" name="title" class="form-control" required="" aria-required="true" th:utext="${model1.title}"></textarea>
                                        <input id="attribute_tv" type="hidden" class="form-control" name="attribute_tv" required="" aria-required="true" th:value="${model1.attribute}" >
                                        <input id="type_tv" type="hidden" class="form-control" name="type_tv" required="" aria-required="true"  th:value="${model1.type}">
                                        <input id="flag_tv" type="hidden" class="form-control" name="flag_tv" required="" aria-required="true"  th:value="${model1.flag}">
                                        <input id="id" type="hidden" class="form-control" name="id" required="" aria-required="true"  th:value="${model1.id}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">副标题：</label>
                                    <div class="col-sm-9">

                                        <textarea id="subtitle" name="subtitle" class="form-control" required="" aria-required="true" th:utext="${model1.subtitle}"></textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">作者：</label>
                                    <div class="col-sm-9">
                                        <input id="author" type="text" class="form-control" name="author" required="" aria-required="true"  th:value="${model1.author}">

                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">类型：</label>
                                    <div class="col-sm-9">
                                        <select class="form-control" name="type" id="type">
                                            <option value="0">原始</option>
                                            <option value="1">网页</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">属性：</label>
                                    <div class="col-sm-9">
                                        <select class="form-control" name="attribute" id="attribute">
                                            <option value="0">普通专题</option>
                                            <option value="1">搭配专题</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">开始时间：</label>
                                    <div class="col-sm-9">
                                        <input id="starttime" type="text" class="form-control" name="starttime" required="" onclick="laydate({elem: '#starttime',format: 'YYYY/MM/DD hh:mm:ss'}); aria-required="true" th:value="${model1.starttime}" >
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">结束时间：</label>
                                    <div class="col-sm-9">
                                        <input id="endtime" type="text" class="form-control" name="endtime" required="" onclick="laydate({elem: '#endtime',format: 'YYYY/MM/DD hh:mm:ss'}); aria-required="true"  th:value="${model1.endtime}">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">状态：</label>
                                    <div class="col-sm-9">
                                        <select class="form-control" name="flag" id="flag">
                                            <option value="0">启用</option>
                                            <option value="-1">下架</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">专题选品库ID：</label>
                                    <div class="col-sm-9">
                                        <input id="fid" type="text" class="form-control" name="fid"   value="0" required="" aria-required="true"   th:value="${model1.fid}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">排序：</label>
                                    <div class="col-sm-9">
                                        <input id="orderno" type="text" class="form-control" name="orderno"   value="0" required="" aria-required="true"   th:value="${model1.orderno}">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">点击数：</label>
                                    <div class="col-sm-9">
                                        <input id="clicks" type="text" class="form-control" name="clicks" value="0" required="" aria-required="true"   th:value="${model1.clicks}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-3">
                                        <button class="btn btn-primary" id="model_submit" type="button">提交</button>
                                        <button class="btn btn-white" id="model_show" type="button">预览</button>
                                    </div>
                                </div>

                            </div>
                        </div>

                    </form>

                    <!-- End Example Events -->



                </div>
            </div>
        </div>

        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="row">
                        <div class="col-sm-10">  <h5>展示图</h5></div>
                        <div class="col-sm-2">
                        </div>
                    </div>
                </div>
                <div class="ibox-content">

                    <div style="height: 390px;align-content: center">
                        <img  id="icon_img" style="max-width: 760px;" th:src="${'http://ou3sldl51.bkt.clouddn.com/'+model1.icon}"/>
                        <input id="icon" type="hidden" class="form-control" name="icon" required="" aria-required="true" th:value="${model1.icon}">

                    </div>
                    <a href="javascript:;" class="file">选择文件
                        <input type="file" name="fileToUpload" id="fileToUpload"  onchange="ajaxFileUpload()" multiple="multiple"/>
                    </a>
                </div>
            </div>
        </div>

    </div>


</div>




<div th:include="footer"></div>

<script type="text/javascript" th:src="@{/script/js/biz/product/favorite.js}"></script>
<script type="text/javascript" th:src="@{/script/js/ajaxfileupload.js}"></script>
<script type="text/javascript" th:src="@{/script/js/ajaxfileupload.js}"></script>
<script>
    $(function () {
        $("#type").val($("#type_tv").val());
        $("#attribute").val($("#attribute_tv").val());
        $("#flag").val($("#flag_tv").val());
        laydate({elem: "#hello",format: "YYYY/MM/DD hh:mm:ss", event: "focus"});
    });




    $("#model_submit").click(function () {
        var id = $("#id").val();
        var title = $("#title").val();
        var subtitle = $("#subtitle").val();
        var type = $("#type").val();
        var icon = $("#icon").val();
        var flag = $("#flag").val();
        var starttime = $("#starttime").val();
        var endtime = $("#endtime").val();
        var clicks = $("#clicks").val();
        var author = $("#author").val();
        var orderno = $("#orderno").val();
        var url = $("#url").val();
        var fid = $("#fid").val();
        var attribute = $("#attribute").val();
        if(title==""){
            toastr.error("请补全信息!");
            return;
        }

        var mydata = '{"id":"'  + id + '","title":"'  + title + '","type":"'+type+'","icon":"'+icon+'","type":"'+type+'","flag":"'+flag+'","starttime":"'+starttime+'","endtime":"'+endtime+'","clicks":"'+clicks+'","orderno":"'+orderno+'"' +
            ',"subtitle":"'+subtitle+'","author":"'+author+'","url":"'+url+'","attribute":"'+attribute+'","fid":"'+fid+'"}';
        $.ajax({
            url: "/common/special/updateSpecial",
            type: "post",
            data: mydata,
            contentType: "application/json",
            dataType:"json",
            success: function (data) {
                if(data["retType"] == "0") {
                    toastr.success("修改成功!");
                    setTimeout( "window.location.href='/common/special/doSpecialPage'",1000);//延时3秒

                } else {
                    toastr.error(data["retMsg"]);
                }
            }
        });
    });


    function ajaxFileUpload() {
        var imgurl = "http://ou3sldl51.bkt.clouddn.com/";
        $.ajaxFileUpload({
            url : '/common/upload/special', //用于文件上传的服务器端请求地址
            secureuri : false, //是否需要安全协议，一般设置为false
            fileElementId : 'fileToUpload', //文件上传域的ID
            type: "post",
            dataType : 'json', //返回值类型 一般设置为json
            success : function(data, status)//服务器成功响应处理函数
            {
                $("#icon_img").attr("src", imgurl+data.key);
                $("#icon").val(data.key);
            },
            error : function(data, status, e)//服务器响应失败处理函数
            {
                toastr.success("文件上传失败!");
            }
        })
        return false;
    }
</script>
</body>
</html>